﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Component;
using DevExpress.Xpo;


public partial class BackEnd_TextStaticList : System.Web.UI.UserControl
{
    public string menuName = "";
    public string url = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        DataBind(Languages.GetAll(true));
        //url = ConvertType.ToString(Session["1"]) + "->" + menu.Name;
        //Session["2"] = " -> <a href=\"" + Request.RawUrl + "\" >" + menu.Name + "</a>";
        grid.RowCancelingEdit += delegate { Response.Redirect(Request.Url.ToString()); };
    }
    #region ----------------------------- Ham viet tay -------------------------------------
    void DataBind(object al)
    {
        if (al != null)
        {
            grid.DataKeyNames = new string[] { ColumTextStatic._Id };
            grid.DataSource = al;
            grid.DataBind();
        }
    }
    #endregion

    protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        object id = grid.DataKeys[e.RowIndex].Value;
        TextBox txtVN = (TextBox)grid.Rows[e.RowIndex].FindControl("txtVN");
        TextBox txtEL = (TextBox)grid.Rows[e.RowIndex].FindControl("txtEL");
        TextBox txtKeyWord = (TextBox)grid.Rows[e.RowIndex].FindControl("txtKeyWord");
        TextStatic textStatic = Languages.GetObjectByid(ConvertType.ToInt(id), true);
        txtVN.Text = textStatic.VN;
        txtEL.Text = textStatic.EL;
        txtKeyWord.Text = textStatic.KeyWord;
        textStatic.Save();
        Response.Redirect(Request.Url.ToString());
    }
    protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grid.EditIndex = e.NewEditIndex;
        DataBind(Component.Languages.GetAll(true));
    }
    protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grid.PageIndex = e.NewPageIndex;
        DataBind(Component.Languages.GetAll(true));
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DataBind(Languages.SearchByKeyWord(this.txtSearch.Text));
    }
    //public void GetAllTextStatic(object sender, EventArgs e)
    //{
    //    DataBind(Languages.GetAll(true));
    //}
    protected void txtSearch_TextChanged(object sender, EventArgs e)
    {
        TextStatic textStatic = new TextStatic(KetNoiCSDL.session);
        ArrayList al = new ArrayList();
        foreach (TextStatic tx in Languages.GetAll(true))
        {
            if (ConvertType.ChuyenDoiCoDauSangKhongDau(tx.VN.ToLower()).Contains(ConvertType.ChuyenDoiCoDauSangKhongDau(this.txtSearch.Text)) == true)
            {
                al.Add(tx);
            }
        }
        DataBind(al);
    }
}
